# coding:utf-8

import re
# def had_number(data):
#     result = re.findall('\d', data) #数字
#     print(result)
#     for i in result:
#         return True
#     return False
#
#
# def remove_number(data):
#     result = re.findall('\D', data) #非数字
#     print(result)
#     return ''.join(result)
#
#
# def startswith(sub, data):
#     _sub = '\A%s' % sub   #开始
#     result = re.findall(_sub, data)
#     for i in result:
#         return True
#     return False
#
# def endswith(sub, data):
#     _sub = '%s\Z' % sub #结束
#     print(_sub)
#     result = re.findall(_sub, data)
#     print(result)
#     if len(result) != 0:
#         return True
#     else:
#         return False
#
#
# def real_len(data):
#     result = re.findall('\S', data) #非空
#     print(result)
#     return len(result)
#
#
#
# if __name__ == '__main__':
#     data = 'i am dewei, i am 33'
#     result = had_number(data)
#     print(result)
#     result = remove_number(data)
#     print(result)
#
#     data = 'hello xiaomu, i am dewei. i am 33 year\'s old'
#     print(re.findall('\W', data))
#
#     result = startswith('hell', data)
#     print(result)
#     result = endswith('olds', data)
#     print(result)
#     print(len(data))
#     result = real_len(data)
#     print(result)



#====================================================================
def check_url(url):
    re_g = re.compile('[a-zA-Z]{4,5}://\w*\.*\w+\.\w+')   #定义一个匹配规则的对象，*表示0次以上。+表示1次以上
    # print(re_g)
    result = re_g.findall(url)
    print(result)
    if len(result) != 0:
        return True
    else:
        return False

def get_url(url):
    re_g = re.compile('[https://|http://](\w*\.*\w+\.\w+)')  # |表示或
    result = re_g.findall(url)
    if len(result) != 0:
        return result[0]
    else:
        return ''


def get_email(data):
    re_g = re.compile('.+@.+\.[a-zA-Z]+')
    result = re_g.findall(data)
    return result


html = ('<div class="s-top-nav" style="display:none;">'
        '</div><div class="s-center-box"></div>')


def get_html_data(data):
    re_g = re.compile('style="(.*?)"')
    result = re_g.findall(data)
    return result

def get_all_data_html(data):
    re_g = re.compile('="(.+?)"')
    result = re_g.findall(data)
    return result


if __name__ == '__main__':
    # result = check_url('http://www.baidu.com/')
    # print(result)
    # result = get_url('https://www.baidu.com/')
    # print(result, 'get_url')
    # result = get_url('http://baidu.com/')
    # print(result, 'get_url')
    # result = get_url('https://com/')
    # print(result, 'get_url')
    # result = get_email('dewei@imooc.net')
    # print(result)
    html = ('<div class="s-top-nav" style="display:none;">'
            '</div><div class="s-center-box"></div>')
    result = get_html_data(html)
    print(result)
    result = get_all_data_html(html)
    print(result)
    re_g = re.compile(('<div class="(.*?)" style="(.*?)">'
        '</div><div class="(.*?)"></div>'))
    result = re_g.search(html)
    print(result.groups())
    print(result.group(1))
    print(result.group(2))
    print(result.group(3))
    # print(result.group(4))
    re_g = re.compile('\s')
    result = re_g.split(html)
    print(result)
    #
    # re_g = re.compile('<div class="(.*?)"')
    # result = re_g.match(html)
    # print(result)
    # print(result.span())
    # print(html[: 22])